<template>
	<view>
		<z-paging ref="paging" v-model="orderList" @query="getPage" :auto="false">
			<cu-custom slot="top" :isBack="true" :bgColor="'bg-'+ theme.themeColor">
				<block slot="backText">返回</block>
				<block slot="content">订单列表</block>
			</cu-custom>
			<scroll-view slot="top" scroll-x class="bg-white nav">
				<view class="flex text-center">
					<view class="cu-item flex-sub" :class="index==tabCur?'cur text-'+ theme.themeColor:''"
						v-for="(item,index) in list" :key="index" @tap="tabSelect(item,$event)" :data-id="index">
						{{item}}
					</view>
				</view>
			</scroll-view>
			<view class="bg-white radius margin-xs newBg" v-for="(item,index) in orderList">
				<navigator hover-class="none" :url="'/subpkg/order/order-detail/index?id=' + item.id">
					
					<view class="flex justify-between align-center padding-xs">
						<!-- 预留店铺名称位置 -->
						<view style="display: flex;align-items: center;">
							<svg t="1697694858930" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4023" width="18" height="17"><path d="M952.786158 352.800941c0-0.516042-0.172014-0.860071-0.172014-1.376113-0.344028-1.892155-0.860071-3.612296-1.548127-5.332437L875.895851 159.285066c-12.901058-38.531161-48.852007-62.613136-93.919704-62.613136L255.440954 96.67193c-44.207626 0-78.610449 23.565933-90.995464 60.720981L83.770872 347.984546c-0.344028 1.204099-0.860071 2.752226-1.204099 4.472367-5.84848 18.061482-8.77272 36.466991-8.77272 55.044515 0 65.193348 35.778935 124.71023 93.231648 155.328742 23.565933 12.729044 51.432219 19.093566 82.738787 19.093566 0 0 0 0 0.172014 0 52.464304-0.172014 101.144297-23.221905 134.34302-62.613136 33.026709 39.219217 81.19066 62.097094 133.654964 62.441122 51.948261-0.344028 100.112212-23.393919 132.966907-62.613136 33.198723 39.563245 81.878717 62.441122 134.687049 62.441122 31.994625-0.172014 60.204939-6.880564 84.1149-19.953637 56.592642-30.96254 91.683521-90.135394 91.683521-154.640685C961.386864 388.235847 958.29061 369.658324 952.786158 352.800941zM766.322862 383.935495 254.408869 383.935495c-17.717453 0-31.994625-14.277171-31.994625-31.994625s14.277171-31.994625 31.994625-31.994625l512.086007 0c17.717453 0 31.994625 14.277171 31.994625 31.994625S784.040316 383.935495 766.322862 383.935495z" fill="#2c2c2c" p-id="4024"></path><path d="M894.989417 639.892491c0-17.717453-14.277171-31.994625-31.994625-31.994625-3.268268 0-6.192508 0.860071-9.288762 1.892155l0 0c-23.737947 9.460776-54.012431 14.449185-76.890307 13.245087-50.400134-2.752226-88.931295-12.729044-125.914329-44.207626-36.466991 31.134554-83.082815 48.852007-132.622879 49.36805-50.22812-0.344028-97.187972-12.901058-133.826978-44.207626-36.983034 31.478582-84.1149 46.787838-134.34302 46.787838l-0.172014 0c-30.618512 0-47.991937-5.84848-75.858223-16.169326-0.688056-0.344028-1.548127-0.516042-2.408198-0.860071-1.376113-0.516042-2.408198-0.860071-3.78431-1.376113 0 0-4.644381-0.860071-7.052579-0.860071 0 0 0 0 0 0-17.717453 0-31.994625 14.449185-31.994625 31.994625l0.172014 171.498068c0 45.067697 36.81102 81.878717 82.050731 81.878717l602.221401-0.344028c45.067697-0.172014 81.878717-36.983034 81.878717-82.050731L894.989417 639.892491z" fill="#2c2c2c" p-id="4025"></path></svg>
							<!-- <text class="cuIcon-title text-red" :class="'text-'+ theme.themeColor"></text> -->
							<text class="text-black">{{item.orderNo}}</text>
							<uni-icons type="right" size="18" color="#000"></uni-icons>
						</view>
					<view class="box-style">
						<view  :class="{'text-red': item.statusDesc === '已取消' || item.statusDesc === '待服务'}">
						  {{item.statusDesc}}
						</view>
					</view>
					


					</view>
					<view class="flex p-xs margin-bottom-sm mb-sm"
						v-for="(itemChild,indexChild) in item.orderItemList" :key="indexChild">
						<view class="basis-xs padding-sm radius">
							<view class="cu-avatar radius xl imgSize" :style="'background-image:url(' + itemChild.picUrl + ')'"></view>
						</view>
						<view class="basis-xl padding-sm radius">
							<view class="hx-overflow-2">
								<text v-if="item.orderType!='1'" class="cu-tag radius sm margin-right-xs"
									:class="'bg-'+ theme.themeColor">{{item.orderTypeDesc}}</text>
								{{itemChild.spuName}}
							</view>
							<view v-if="itemChild.specsInfo" class="text-gray">
								{{itemChild.specsInfo}}
							</view>
							<view class="flex justify-between align-end padding-top-xs">
								<view class="text-bold text-df " :class="'text-'+ theme.themeColor">  <!-- text-price -->
									<!-- {{itemChild.salesPrice}} -->
								</view>
								<view style="color: #9E9E9E;"> x{{itemChild.buyQuantity}}</view>
							</view>
							<view class="flexRigth">
								￥{{itemChild.salesPrice}}
							</view>
							<view class="flex justify-end padding-top-xs">
								<navigator @click.prevent.stop="" v-if="itemChild.status >0" class="cu-btn sm round "
									hover-class="none" :class="'bg-'+theme.matchColor"
									:url="'/pages/order/order-refund/index?orderItemId=' + itemChild.id">
									{{itemChild.statusDesc}}
								</navigator>
							</view>

						</view>
					</view>
					<!-- <view class="flex justify-end padding-xs">
						<view>
							<text>总价</text>
							<text class="text-price"> {{item.totalPrice}}</text>
						</view>
						<view v-if="item.couponPrice >0" class="padding-left-xs">
							<text>,优惠</text>
							<text class="text-price"> {{item.couponPrice}}</text>
						</view>
						<view class="padding-lr-xs">
							<text>,实付</text>
							<text class="text-price text-bold text-red text-lg padding-lr-xs">
								{{item.paymentPrice}}</text>
						</view>
					</view> -->
				</navigator>
				<view class="flex border justify-end">
					<order-operation :orderInfo="item" @orderDel="orderDel($event,index)"
						@orderReceiver="orderReceiver($event,index)" @orderCancel="orderCancel($event,index)">
					</order-operation>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	import orderOperation from 'components/order-operation/index'
	import {
		getPage,
		getById
	} from '@/api/orderinfo.js';
	export default {
		components: {
			orderOperation
		},
		data() {
			return {
				theme: getApp().globalData.theme,
				orderList: [],
				list: ['全部', '待付款', '待服务','待评价','已取消'],
				status: 0,
				tabCur: 0,
				appraiseStatus:0
			}
		},
		
		onLoad(option) {
			getApp().initPage().then(res => {
				if (option.status) {
					
					if(option.status === "3"){
						this.status = "4"
					}
					
					this.tabCur = option.status;
					
					this.status = option.status
				}
			})
		},
		onShow() {
			this.$nextTick(function() {
				this.$refs.paging.reload();
			})
		},
		methods: {
			tabSelect(item, e) {
				
			  this.tabCur = e.currentTarget.dataset.id;
			  
			  if (item === '已取消') {
			    this.status = 11;
			  } else if (item === '待评价') {
			    this.status = 4
			  } else {
			    this.status = e.currentTarget.dataset.id;
			  }
			  console.log( this.tabCur )
			  this.$refs.paging.reload();
			},
			/**
			 * 分页查询
			 */
			getPage(pageNo, pageSize) {
				getPage({
					current: pageNo,
					size: pageSize,
					descs: 'create_time',
					status: this.status == 0 ? '' : this.status,
					appraiseStatus: this.appraiseStatus
				}).then(res => {
					this.$refs.paging.complete(res.data.records);
				});
			},
			sectionChange(index) {
				this.status = index
				this.$refs.paging.reload();
			},
			orderDel(item, index) {
				this.orderList.splice(index, 1);
			},
			orderReceiver(item, index) {
				this.$refs.paging.reload();
			},
			orderCancel(item, index) {
				getById(item.id).then(res => {
					this.$set(this.orderList, index, res.data);
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F7F7F7;
	}
	.flexRigth{
		display: flex;
		justify-content: flex-end;
		font-weight: bold;
		color: #333333;
		font-size: 17px;
		margin-top: 10px;
	}
	.item-bottom {
		display: flex;
		justify-content: flex-end;
		align-items: center;
		padding: 20rpx;
		.price {
			color: red;
		}

		.pay-price {
			font-size: 38rpx;
		}
	}
	.text-red{
		color: #FFA954 !important;
		font-size: 13px !important;
	}
	.imgSize{
		width: 191rpx;
		height: 191rpx;
		border-radius: 6rpx;
	}
	.newBg{
		width: 703rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 2rpx 27rpx 1rpx rgba(0,0,0,0.03);
		border-radius: 12rpx;
		margin: 11.72px auto;
		padding: 21.09rpx 25.78rpx;
	}
	.box-style{
		color: #C4C4C4 !important;
		font-size: 13px !important;
	}
</style>
